<template>
	<view class="pay-error-detail">
		<view class="content-wrapper">
			<p>异常单号：{{info.billid}}</p>
			<p>患者姓名：{{info.itemData.PatientName}}</p>
			<p>开单科室：{{info.itemData.Department}}</p>
			<p>开单医生：{{info.itemData.Doctor}}</p>
			<p>支付金额：{{info.money}}</p>
			<p>流程节点：{{flowFlag(info.flowFlag)}}</p>
			<p>支付单号：{{info.id}}</p>
		</view>
		<u-button v-if="info.flowFlag > 2" type="error" text="退款" @click="refund(info.id)"></u-button>
		
		<yangr-msg v-if="yangrMsgShow" :title="yangrMsgTitle" type="error" :info="yangrMsgMessage" btn="确定"
			@yangrMsgEvent="closeYangrMsg"></yangr-msg>
	</view>
</template>

<script>
	import _ from 'lodash'
	import yangrMsg from "@/components/yangr-msg/yangr-msg.vue"
	export default {
		data() {
			return {
				info: {},
				
				yangrMsgTitle: '操作失败',
				yangrMsgMessage: '',
				yangrMsgShow: false
			}
		},
		onLoad(option) {
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('detail', (data) => {
				this.info = data.data
				console.log(this.info)
			})
		},
		onShow() {
			
		},
		methods: {
			closeYangrMsg() {
				this.yangrMsgShow = false
			},
			flowFlag(flag) {
				if (flag == 1) {
					return '发起订单'
				}else if (flag == 2) {
					return '发起支付，但未支付'
				}else if (flag == 3) {
					return '已支付金额'
				}else if (flag == 4) {
					return '支付完成更新订单状态'
				}else if (flag == 5) {
					return '完成缴费并下单'
				}
			},
			test() {
				let payFlows = uni.getStorageSync('payFlows')
				_.remove(payFlows, (item) => {
					return item.id == this.info.id
				})
				uni.setStorageSync('payFlows', payFlows)
			},
			refund(id) {
				let openid = uni.getStorageSync('openid')
				uni.showModal({
					title: '提示',
					content: '确定要退款吗？',
					success: (res) => {
						if (res.confirm) {
							this.$app._post_form2('entry/wxapp/apipayment.billrefundbyid', {
								openid: openid,
								id: id
							}, (res) => {
								if (res.status == 0) {
									let payFlows = uni.getStorageSync('payFlows')
									_.remove(payFlows, (item) => {
										return item.id == this.info.id
									})
									uni.setStorageSync('payFlows', payFlows)
									uni.navigateTo({
										url: '/pages/global/successMessage?msg=退款成功'
									})
								}else {
									// uni.showToast({
									// 	icon: 'none',
									// 	title: '退款失败'
									// })
									this.yangrMsgShow = true
									this.yangrMsgMessage = '退款失败：'+res.data.return_msg
								}
							})
						} else if (res.cancel) {
				
						}
					}
				});
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.pay-error-detail {
		width: 100%;
		height: 100%;
		position: relative;
		color: #757575;
		padding: 15px;
		box-sizing: border-box;

		.content-wrapper {
			border-radius: 6px;
			border: 1px solid #e3e3e3;
			padding: 10px;
			line-height: 30px;
			background-color: #f5f5f5;
			font-size: .8rem;
			color: #757575;
			margin-bottom: 10px;

			p {
				display: block;
			}
		}


	}
</style>